package com.example.datajpa.controller;

import com.example.datajpa.domain.Person;
import com.example.datajpa.repository.CustomPersonRepository;
import com.example.datajpa.repository.CustomRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author ljw
 * @description
 * @date 2022/6/13 7:56
 */
@RestController
@RequestMapping("/customperson")
public class CustomPersonController {

    @Autowired
    private CustomPersonRepository customPersonRepository;

    @RequestMapping("/auto")
    public Page<Person> auto(Person person) {
        Page<Person> pagePeople = customPersonRepository.findByAuto(person, PageRequest.of(0, 10));
        return pagePeople;
    }

    @GetMapping("/findByAddress")
    public List<Person> findByAddress(@RequestParam String address) {
        List<Person> personList = customPersonRepository.findByAddress(address);
        return personList;
    }
}
